from django.db import models
from django.utils import timezone
from DjangoUeditor.models import UEditorField


# Create your models here.
class Product(models.Model):
    PRODUCTS_CHOICES = (('1', '家用机器人'), ('2', '智能监控'), ('3', '人脸识别解决方案'))
    id = models.AutoField('编号', primary_key=True)  # 主键自增配置
    productType = models.CharField('产品类别', choices=PRODUCTS_CHOICES, max_length=50)  # 后台选择
    title = models.CharField('标题', max_length=50)
    desc = models.TextField('介绍')
    price = models.DecimalField('价格', decimal_places=2, max_digits=7)
    pubDate = models.DateTimeField('发布日期', default=timezone.now)

    def __str__(self):
        return self.title

    class Meta:  # django 的后台
        verbose_name = '产品'
        verbose_name_plural = '产品'


# 图片(多张)
class ProductImg(models.Model):
    product = models.ForeignKey(Product, related_name='productImgs', verbose_name='产品', on_delete=models.CASCADE)
    photo = models.ImageField(upload_to='product/', blank=True, verbose_name='产品图片')

    class Meta:
        verbose_name = '产品图片'
        verbose_name_plural = '产品图片'


# 新闻模型
class News(models.Model):
    NEW_CHOICES = (('1', '企业要闻'), ('2', '行业新闻'), ('3', '通知公告'))
    id = models.AutoField('编号', primary_key=True)
    newType = models.CharField('新闻类型', choices=NEW_CHOICES, max_length=50)
    title = models.CharField('标题', max_length=50)
    content = UEditorField('内容', width=1000, imagePath='news/images/', filePath='news/files/', toolbars='mini')
    pubDate = models.DateTimeField('发布日期', default=timezone.now)

    def __str__(self):
        return self.title

    class Meta:  # django 的后台
        verbose_name = '新闻'
        verbose_name_plural = verbose_name
